package leetcode.code0748;

public class Solution extends Solution748 {

	@Override
	public String shortestCompletingWord(String licensePlate, String[] words) {
		int[] dics = this.dics(licensePlate);
		int len = Integer.MAX_VALUE;
		String ans = "";
		for (String word : words) {
			int[] tmp = this.dics(word);
			if (this.compare(dics, tmp)) {
				if (word.length() < len) {// 最靠前且短的单词
					len = word.length();
					ans = word;
				}
			}
		}
		return ans;
	}

	private boolean compare(int[] dics, int[] tmp) {// 选择合规的单词
		for (int i = 0; i < 26; i++) {
			if (dics[i] > tmp[i]) {
				return false;
			}
		}
		return true;
	}

	private int[] dics(String s) {// 单词有效数量
		int[] dics = new int[26];
		for (char c : s.toCharArray()) {
			if (c >= 'a' && c <= 'z') {
				dics[c - 'a']++;
			} else if (c >= 'A' && c <= 'Z') {
				dics[c - 'A']++;
			}
		}
		return dics;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		so.debug5();
		System.out.println((int) 'a');
		System.out.println((int) 'A');
		System.out.println('a' - 'A');
	}

}
